<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>来个好玩的</button>
    <button>下去吧</button>
    <hr>

    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            state = {
                src: 'http://api.xiaohigh.com/video/random'
            }
            //render 方法  渲染, 挂载  
            render(){
                console.log('3-挂载中....');
                return <div>
                        <video src={this.state.src} onClick={this.change} controls={true} width="300"></video>
                    </div>
            }

            change =() => {
                this.setState({
                    src: 'http://api.xiaohigh.com/video/random?t='+Date.now()
                })
            }


            constructor(){
                super();//
                console.log('1-构造方法')
            }

            //组件将要挂载
            componentWillMount(){
                console.log('2-组件将要挂载');
            }

            //组件完成挂载
            componentDidMount(){
                console.log('4-组件完成挂载');
            }


        }

        //获取按钮
        let btns = document.querySelectorAll('button');
        //第一个按钮绑定单击事件
        btns[0].onclick = function(){
            ReactDOM.render(<App />, document.querySelector("#root"));
        }

        btns[1].onclick = function(){
            ReactDOM.unmountComponentAtNode(document.querySelector("#root"));
        }

    </script>
</body>
</html>